package com.hmz.backend.controller.chat;

import cn.hutool.json.JSONObject;
import com.hmz.backend.service.chat.MessageService;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
public class MessageController {
    @Value("${PageSize}")
    int pageSize;
    @Autowired
    MessageService messageService;
    //获取聊天记录
    @GetMapping("/getPrivateMessage")
    public JSONObject getPrivateMessage(@RequestParam int chatRoomId){
        System.out.println("获取私聊消息接口");
        return messageService.getPrivateMessage(chatRoomId);
    }
    //获取更早的消息记录一次返回10条，从Mysql中拿
    @GetMapping("/getOldMessage")
    public JSONObject getOldMessage(@RequestParam int chatRoomId, @RequestParam int pageNow){
        System.out.println("获取更早的消息记录调用");
        return messageService.getOldMessage(chatRoomId,pageNow,pageSize);
    }
    @GetMapping("/getUserMessageListInChatRoom")
    public JSONObject getUserMessageListInChatRoom(@RequestParam int chatRoomId,@RequestParam int userId){
        System.out.println("获取指定聊天室下指定用户的所有发言");
        return messageService.getUserMessageListInChatRoom(chatRoomId, userId);
    }
    @GetMapping("/getTimeListInChatRoom")
    public JSONObject  getTimeListInChatRoom(@RequestParam int chatRoomId){
        System.out.println("获取指定聊天室下所有的日期列表");
        return messageService.getTimeListInChatRoom(chatRoomId);
    }
    @GetMapping("/getTypeMessageListInChatRoom")
    public JSONObject getTypeMessageListInChatRoom(@RequestParam int chatRoomId, @RequestParam int type){
        System.out.println("获取指定聊天室下指定类型的聊天记录");
        return messageService.getTypeMessageListInChatRoom(chatRoomId,type);
    }
    @GetMapping("/getTimeMessageListInChatRoom")
    public JSONObject getTimeMessageListInChatRoom(@RequestParam int chatRoomId, @RequestParam String date){
        System.out.println("获取指定聊天室下指定时间的聊天记录");
        System.out.println(chatRoomId+" "+date);
        return messageService.getTimeMessageListInChatRoom(chatRoomId,date);
    }

}
